const { Menu } = antd;
const { SubMenu } = Menu;

const Admin_sidebar = React.createClass({
    getInitialState(){
        return({
            current: '0',
            openKeys: [],
            data: left_menu
        });
    },
    handleClick(e) {
        this.setState({
            current: e.key,
        });
    },
    render() {
        let data = this.state.data;
        let menus = [];
        let openKeys = [];
        if(data!=null){
            let key = 0;
            let baseUrl = getBaseUrl();
            menus = data.map(function(val){
                let sub = [];
                if(val.children!=null){
                    if(typeof val.dynamic_hide === 'undefined'){
                        sub = val.children.map(function(val){
                            let link = U(val.url,{activesubmenuid: val.id});
                            return(
                                <Menu.Item key={++key}>
                                    <a href={link}>{val.title}</a>
                                </Menu.Item>
                            );
                        });
                    }
                }
                openKeys.push(val.id);
                return(
                    <SubMenu key={val.id} title={<span><span>{val.title}</span></span>}>
                        {sub}
                    </SubMenu>
                );
            });
        }
        return (
            <Menu onClick={this.handleClick}
                  defaultOpenKeys={openKeys}
                  selectedKeys={[this.state.current]}
                  mode="inline"
            >
                {menus}
            </Menu>
        );
    }
});